package com.translate;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串验证相关方法
 *
 * @author Nancy
 */
public class StringUtils {

    /**
     * 判断字符串是否有效
     *
     * @param strParam ""
     * @return ""
     */
    public static boolean isValid(String... strParam) {
        if (null == strParam) {
            return false;
        } else {
            boolean isValid = false;
            for (String str : strParam) {
                if (null == str || ("").equals(str.trim()) || ("null").equals(str.trim()) || str.length() == 0) {
                    isValid = false;
                    break;
                } else {
                    isValid = true;
                }
            }
            return isValid;
        }
    }

    /**
     * 判断字符串是否有效
     *
     * @param strParam ""
     * @return ""
     */
    public static boolean isValid(Object... strParam) {
        if (null == strParam) {
            return false;
        } else {
            boolean isValid = false;
            for (Object str : strParam) {
                if (null == str || ("").equals(str.toString().trim()) || ("null").equals(str.toString().toLowerCase().trim()) || str.toString().length() == 0) {
                    isValid = false;
                    break;
                } else {
                    isValid = true;
                }
            }
            return isValid;
        }
    }

    /**
     * 判断Object类型字符串是否为空
     *
     * @param strParam ""
     * @return ""
     */
    public static boolean isNotEmpty(Object strParam) {
        return strParam != null && !"".equals(strParam) && !"null".equals(strParam.toString().toLowerCase());
    }

    /**
     * 判断Object类型字符串是否为空
     *
     * @param strParam ""
     * @return ""
     */
    public static boolean isEmpty(Object strParam) {
        return strParam == null || "".equals(strParam) || "null".equals(strParam.toString().toLowerCase());
    }

    /**
     * @param filename ""
     * @return ""
     */
    public static String getFileNameNoEx(String filename) {
        if ((filename != null) && (filename.length() > 0)) {
            int dot = filename.lastIndexOf('.');
            if ((dot > -1) && (dot < (filename.length()))) {
                return filename.substring(0, dot);
            }
        }
        return filename;
    }

    /**
     * @param number ""
     * @return ""
     */
    public static boolean isNumber(String number) {
        int length = 8;
        if (number.length() > length) {
            return false;
        }
        String rexp = "^(-?\\d+)(\\.\\d+)?$";
        Pattern pat = Pattern.compile(rexp);
        Matcher mat = pat.matcher(number);
        boolean dateType = mat.matches();
        return dateType;
    }
    public static String trim(String str) {
        return str == null ? null : str.trim();
    }
}
